package com.cxc.demo.impl;

import com.cxc.demo.dto.Person;
import com.cxc.demo.dto.PersonDTO;
import com.cxc.demo.mapper.PersonMapper;

import java.sql.Date;
import java.text.SimpleDateFormat;

public class PersonMapperImpl implements PersonMapper {

    public PersonMapperImpl(){}
    @Override
    public PersonDTO conver(Person person) {
        if (null==person){
            return null;
        }else{
            PersonDTO personDTO = new PersonDTO();

            if (null!=person.getDescribe()){
                personDTO.setDescribe(person.getDescribe());
            }

            if (person.getId() != null) {
                personDTO.setId(Long.parseLong(person.getId()));
            }
            personDTO.setPersonName(person.getName());
            personDTO.setAge(String.valueOf(person.getAge()));
            if (person.getSource() != null) {
                personDTO.setSource(person.getSource().toString());
            }
            try {
                if (person.getCreateTime() != null) {
                    personDTO.setCreateTime(String.valueOf((new SimpleDateFormat("yyyy-MM-dd")).
                            parse(person.getCreateTime())));
                }
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
            personDTO.setHeight(String.valueOf(person.getHeight()));
            return personDTO;

        }


    }
}
